<template>
	<view>
		<uni-forms :modelValue="Income">
			<uni-forms-item label="ID" v-if="false" >
				<uni-easyinput v-model="Income.incomeId" />
			</uni-forms-item>
			<uni-forms-item label="用户ID" v-if="false" >
				<uni-easyinput v-model="Income.userId"/>
			</uni-forms-item>
			<uni-forms-item label="描述">
				<uni-easyinput  v-model="Income.incomeDescription" />
			</uni-forms-item>
			<uni-forms-item label="金额">
				<uni-easyinput type="number" v-model="Income.incomeAmount" />
			</uni-forms-item>	
			<uni-forms-item label="日期时间">
				<uni-datetime-picker type="datetime" v-model="Income.incomeDate"/>
			</uni-forms-item>
			<uni-forms-item label="收入类别">
				<uni-easyinput v-model="Income.incomeCategory" />
			</uni-forms-item>		
		</uni-forms>
		<button type="primary" size="mini" @click="submit()">保存</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Income: {
					incomeId:"",
					userId:"",
					incomeDescription:"",
					incomeDate:"",
					incomeCategory:"",
					incomeAmount:"",
					year:"",
					month:"",
					token:""
				}
			}
		},
		onLoad() {
			uni.getStorage({
				key:'token',
				success: res=>{
					// console.log(res.data);
					this.token=res.data
				}
			});
			uni.getStorage({
				key : 'user',
				success: res=>{
					console.log(res.data.userId);
					this.Income.userId=res.data.userId
				}
			});
		},
		methods: {
			submit(){
				console.log(this.Income),
				uni.request({
					url:'http://8.130.170.106:9999/income/insert',
					data:{
						userId: this.Income.userId,
						incomeDescription: this.Income.incomeDescription,
						incomeAmount: this.Income.incomeAmount,
						incomeDate: this.Income.incomeDate,
						incomeCategory: this.Income.incomeCategory
					},
					header:{
						token:this.token
					},
					success: (res) => {
						uni.navigateTo({
							url: '/pages/main/tabbar-3-detial/tabbar-3-income/tabbar-3-income',
							success: () => {
							  console.log("跳转成功");
							},
							fail: (err) => {
							  console.log("跳转失败", err);
							}
						});
					}
				})
			}
		}
	}
</script>

<style>
	.incomeDescription {
	  font-weight: bold;
	  font-size: 16px;
	}
	.button {
			display: flex;
			align-items: center;
			height: 35px;
			margin-left: 10px;
		}
</style>
